package com.org.platform.support.conponents;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Description
 * @auther dh
 * @date 2022/3/12 10:08
 */
@Slf4j
@Component
public class SpringApplicationContextAware implements InitializingBean, ApplicationContextAware {
	public static ApplicationContext applicationContext = null;

	@Override
	public void afterPropertiesSet() throws Exception {
		log.info("InitializingBean success");
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		synchronized (SpringApplicationContextAware.class) {
			if (this.applicationContext == null) {
				this.applicationContext = applicationContext;
			}
		}
		log.info("InitializingApplicationContextAware success");
	}

	public static ApplicationContext getApplicationContext() {
		return applicationContext;
	}

}
